<script>
import axios from 'axios'
export default {
  name: 'LoginView',
  data () {
    return {
      loginInfo: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    login () {
      const params = new URLSearchParams()
      params.append('username', this.loginInfo.username)
      params.append('password', this.loginInfo.password)
      axios({
        url: '/api/login',
        method: 'post',
        data: params
      }).then(res => {
        console.log(res)
      }).catch(e => console.log(e))
    },
    login2 () {
      axios({
        url: '/api/login',
        method: 'post',
        data: this.loginInfo
      }).then(res => {
        console.log(res)
      }).catch(e => console.log(e))
    }
  }

}
</script>

<template>
<div>
  <form>
    <div>
      <label for="username">用户名</label>
      <input type="text" id="username" v-model="loginInfo.username" placeholder="请输入用户名">
    </div>
    <div>
      <label for="password">密码</label>
      <input type="password" id="password" v-model="loginInfo.password" placeholder="请输入密码">
    </div>
    <div>
      <button type="button" @click="login">登录</button>
      <button type="button" @click="login2">登录2</button>
    </div>
  </form>
</div>
</template>

<style scoped lang="scss">

</style>
